import React, { Component } from 'react'
import Counter from './Counter';
import Button from '../base/Button';

class CounterFather extends Component {
  constructor (props) {
    super (props)
    this.initCount = [132,12,30]
    this.initSum = this.initCount.reduce(function (a,b) {
      return a+b 
    })
    this.state = {
      sum: this.initSum
    }
    this.getNum = this.getNum.bind(this)
  }
  getNum (news, old) {
    const newVal =  news - old
    console.log(news,old)
    this.setState({
      sum: this.state.sum + newVal
    })
  }
  handleClick = () => {
    alert(1)
  }
  render () {
    return (
      <div>
        <Button style='btn-sm-solid' value="+ 按钮" onClick={this.handleClick} />
        <Counter getNum = {this.getNum} txt="One" initCount={this.initCount[0]} />
        <Counter txt="Two" getNum = {this.getNum} initCount={this.initCount[1]} />
        <Counter txt="Two" getNum = {this.getNum} initCount={this.initCount[2]} />
        合计： {this.state.sum}
      </div>
    )
  }
}

export default CounterFather